package com.zhanqiao.controller;

import com.alibaba.fastjson.JSON;
import com.zhanqiao.domain.ProductBean;
import com.zhanqiao.domain.ResponseBean;
import com.zhanqiao.service.SelectReturnProductService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

@WebServlet("/selectreturnproduct.action")
public class SelectReturnProductController extends HttpServlet {
    private SelectReturnProductService selectStatedContentService = new SelectReturnProductService();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("application/json;charset=utf8");
        try {
            List<ProductBean> products = selectStatedContentService.articleService(req.getParameter("page"), req.getParameter("limit"));
            Long count = selectStatedContentService.getProductCount();
            ResponseBean responseBean = new ResponseBean();
            responseBean.setCode(0);
            responseBean.setMsg("");
            responseBean.setCount(count);
            responseBean.setData(products);
            String ret = JSON.toJSONString(responseBean);
            resp.getWriter().write(ret);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
